﻿Option Strict Off
Option Explicit On

Namespace Blog

    <CLSCompliant(True)> _
    Public Class Tag

        Inherits BlogSpark.Common.ObjectBase

#Region "Members"

        Private _TagId As Integer = 0
        Private _Title As String
        Private _Url As String
        Private _Created As DateTime
        Private _Modified As DateTime

#End Region

#Region "Constructors"

        Public Sub New()
        End Sub

#End Region

#Region "Methods"

        Public Overrides Sub Fill(ByVal dr As System.Data.DataRow)

            _TagId = dr(enumTagFields.TagID)
            Title = dr(enumTagFields.title)
            URL = dr(enumTagFields.Url)
            Created = dr(enumTagFields.Created)
            Modified = dr(enumTagFields.Modified)

        End Sub

        Public Sub Save()

            If _TagId = 0 Then
                _TagId = BlogSpark.DataProvider.SPs.InsertTag(BlogSpark.DataProvider.Data.ConnectionType, Title, URL, Created, Modified)
            Else
                BlogSpark.DataProvider.SPs.UpdateTag(BlogSpark.DataProvider.Data.ConnectionType, TagID, Title, URL, Created, Modified)
            End If

        End Sub

        Public Sub Delete()

            BlogSpark.DataProvider.SPs.DeleteTag(BlogSpark.DataProvider.Data.ConnectionType, TagID)

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property TagID() As Integer
            Get
                Return _TagId
            End Get
        End Property

        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Public Property URL() As String
            Get
                Return _Url
            End Get
            Set(ByVal value As String)
                _Url = value
            End Set
        End Property

        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

        Public Property Modified() As DateTime
            Get
                Return _Modified
            End Get
            Set(ByVal value As DateTime)
                _Modified = value
            End Set
        End Property

#End Region

#Region "Enums"

        Private Enum enumTagFields As Byte

            TagID = 0
            title
            Url
            Created
            Modified

        End Enum

#End Region

    End Class

End Namespace

